package com.zyit.web;

import com.zyit.DataObject.T_user;
import com.zyit.entity.T_base_order;
import com.zyit.entity.T_goods;
import com.zyit.service.Impl.OderNoServiceImpl;
import com.zyit.service.Impl.UserOrderServiceImpl;
import com.zyit.service.OderNoService;
import com.zyit.service.UserOrderService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/user")
public class UserOrderServlet extends HttpServlet {
    private UserOrderService userOrderService = new UserOrderServiceImpl();
    private OderNoService oderNoService = new OderNoServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = request.getSession();
        T_user user = (T_user) session.getAttribute("userI");
        String account = user.getAccount();

        System.out.println("登录界面");
        System.out.println("用户名称为:"+account);

        List<T_goods> t_goods = (List<T_goods>) userOrderService.findById(account);
        request.setAttribute("t_goods", t_goods);


        List<T_base_order> t_base_orders = oderNoService.findAll(account);
        HttpSession session1 = request.getSession();
        session1.setAttribute("t_base_orders",t_base_orders);
        request.getRequestDispatcher("/manager/order/orderList.jsp").forward(request, resp);

    }
}
